package com.lagou.session;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;

/**
 * @author srh
 * @date 2020/02/22
 **/
public interface SqlSession {

    /**
     * 查询列表
     *
     * @param statementId
     * @param params
     * @param <T>
     * @return
     */
    <T> List<T> selectList(String statementId, Object... params) throws InvocationTargetException, SQLException, IntrospectionException, InstantiationException, IllegalAccessException, NoSuchFieldException;

    /**
     * 单条查询
     *
     * @param statementId
     * @param params
     * @param <T>
     * @return
     */
    <T> T selectOne(String statementId, Object... params) throws InvocationTargetException, SQLException, IntrospectionException, InstantiationException, IllegalAccessException, NoSuchFieldException;

    /**
     * 更新操作
     *
     * @param statementId
     * @param params
     * @return
     */
    int update(String statementId, Object... params) throws InvocationTargetException, SQLException, IntrospectionException, InstantiationException, IllegalAccessException, NoSuchFieldException;

    /**
     * 新增操作
     *
     * @param statementId
     * @param params
     * @return
     */
    int insert(String statementId, Object... params) throws SQLException, NoSuchFieldException, IllegalAccessException;

    /**
     * 删除
     *
     * @param statementId
     * @param params
     * @return
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws IllegalAccessException
     */
    int delete(String statementId, Object... params) throws SQLException, NoSuchFieldException, IllegalAccessException;

    /**
     * 获取dao层的代理对象
     *
     * @param mapperClass
     * @param <T>
     * @return
     */
    <T> T getMapper(Class<?> mapperClass);

    /**
     * 释放资源
     */
    void close() throws SQLException;

    void commit() throws SQLException;
}
